package com.wkr.controller;

import com.wkr.tool.sender;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class testController {
    private static final Logger log = LoggerFactory.getLogger(testController.class);
    @Autowired
    sender senders;

    @Scheduled(cron = "0/10 * * * * ?")//每隔10秒隔行一次
    public void Hello() {
        try {
            JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
            Client client = dcf.createClient("http://localhost:8090/service/RemoteService?wsdl");
            client.invoke("say");
        } catch (Exception e) {
            e.printStackTrace();
            log.info("动态调用WebService接口失败！");
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        senders.sendMessage(simpleDateFormat.format(new Date()));
    }
}
